﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DotNet.Business;
using DotNet.Common;
using DotNet.Model;
public partial class Admin_EditTab : System.Web.UI.Page
{
    productBll pBll = new productBll();
    ProductTabBll ptBll = new ProductTabBll();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["productid"]!=null)
            {
                this.ProductID.Value = Request.QueryString["productid"].ToString();
                product productModel = pBll.GetModel(Convert.ToInt32(Request.QueryString["productid"]));
                Session["FCKeditor:UserFilesPath"] = "~/UploadFiles/productUpload/" + productModel.Productmodel;
                this.productName_span.InnerText =  productModel.productName;
                BindTab();
            }
            if (Request.QueryString["state"]!=null)
            {
                string state = Request.QueryString["state"].ToString();
                switch (state.Trim())
                {
                    case "update":
                        update();
                        break;
                    default:
                        break;
                }
            }
        }
    }
    public void update() 
    {
        ProductTab pt = new ProductTab();
        pt.productID = Convert.ToInt32(Request.Form["productid"]);
        pt.tabID = Convert.ToInt32(Request.Form["tabid_hid"]);
        pt.tabTitle = Request.Form["TabTitle_txt"].ToString();
        if (pt.tabTitle == "")
        {
            Response.Write("tab标题不能为空！");
            Response.End();
        }
        if (Request.Form["TabSort"] == "")
        {
            Response.Write("tab顺序不能为空！");
            Response.End();
        }
        if (!CommUtil.IsNumStr(Request.Form["TabSort"]))
        {
            Response.Write("tab顺序必须为数字！");
            Response.End();
        }
        pt.tabSort = Convert.ToInt32(Request.Form["TabSort"]);
        if (Request.Form["FCKeditor1"] == "")
        {
            Response.Write("tab内容不能为空！");
            Response.End();
        }
        pt.tabContent = Server.HtmlDecode(Request.Form["FCKeditor1"].ToString());
        CommUtil.ValidID(pt.tabSort.ToString());
        if (ptBll.Update(pt))
        {
            Response.Write("1");
        }
        else
        {
            Response.Write("修改错误！！");
        }
        Response.End();
    }
    public void BindTab() 
    {
        ProductTab pt = ptBll.GetModel(Convert.ToInt32(Request.QueryString["tid"]));
        this.TabTitle_txt.Value = pt.tabTitle;
        this.TabSort.Value = pt.tabSort.ToString();
        this.FCKeditor1.Value = pt.tabContent;
        this.tabid_hid.Value = Request.QueryString["tid"].ToString();
    }
}
